import {lazy, Suspense} from 'react';
import {createBrowserRouter} from "react-router-dom";
// import {AuthRoute} from "/components/AuthRoute";
// 1. 使用lazy函数引入组件 实现路由懒加载
const Home = lazy(() => import("@/pages/Home/index.jsx"));
const Management = lazy(() => import("@/pages/User/Management/index.jsx"));
const Census = lazy(() => import("@/pages/User/Census/index.jsx"));
const Hot = lazy(() => import("@/pages/Commodity/Hot/index.jsx"));
const Register = lazy(() => import("@/pages/Register/index.jsx"));
const Login = lazy(() => import("@/pages/Login/index.jsx"));
const Authority = lazy(() => import("@/pages/Admin/Authority/index.jsx"));
const Information = lazy(() => import("@/pages/Admin/Information/index.jsx"));
const NotFond = lazy(() => import("@/pages/404/index.jsx"));
const Swiper = lazy(() => import("@/pages/Commodity/Swiper/index.jsx"));
const Me = lazy(() => import("@/pages/Me/index.jsx"));
const FirstHome = lazy(() => import("@/pages/FirstHome/index.jsx"));
const Message = lazy(() => import("@/pages/Message/index.jsx"));
const About = lazy(() => import("@/pages/About/index.jsx"));
const Log = lazy(() => import("@/pages/Log/index.jsx"));
const fallback = <h3>别着急，我正在拼命加载中...</h3>;
// 创建路由实例
export const router = createBrowserRouter([
    {
        path: "/",
        element: <Home/>,
        children: [
            {
                index: true,
                element: <Suspense fallback={fallback}><FirstHome/></Suspense>,
            },
            {
                path: "/commodity/swiper",
                element: <Suspense fallback={fallback}><Swiper/></Suspense>,
            },
            {
                path: "/commodity/hot",
                element: <Suspense fallback={fallback}><Hot/></Suspense>,
            },
            {
                path: "/user/census",
                element: <Suspense fallback={fallback}><Census/></Suspense>
            },
            {
                path: "/user/management",
                element: <Suspense fallback={fallback}><Management/></Suspense>
            },
            {
                path: "/shopping/breakdown",
                element: <div>分类管理</div>,
            },
            {
                path: "/shopping/order",
                element: <div>订单管理</div>,
            },
            {
                path: "/shopping/coupon",
                element: <div>优惠卷管理</div>,
            },
            {
                path: "/admin/information",
                element: <Suspense fallback={fallback}><Information/></Suspense>,
            },
            {
                path: "/admin/management",
                element: <Suspense fallback={fallback}><Authority/></Suspense>,
            },
            {
                path: "/system/about",
                element: <Suspense fallback={fallback}><About/></Suspense>
            },
            {
                path: "/system/set",
                element: <div>设置</div>,
            },
            {
                path: "/system/me",
                element: <Suspense fallback={fallback}><Me/></Suspense>,
                children: [
                    {
                        index: true,
                        element: <div>我的主页</div>,
                    },
                    {
                        path: "/system/me/password",
                        element: <div>修改密码</div>,
                    },
                    {
                        path: "/system/me/article",
                        element: <div>我的笔记</div>,
                    },
                    {
                        path: "/system/me/setting",
                        element: <div>我的设置</div>,
                    },
                    {
                        path: "/system/me/star",
                        element: <div>我的收藏</div>,
                    },
                    {
                        path: "/system/me/comment",
                        element: <div>我的评论</div>,
                    },
                    {
                        path: "/system/me/avatar",
                        element: <div>更换头像</div>,
                    }
                ]
            },
            {
                path: "/system/log",
                element: <Suspense fallback={fallback}><Log/></Suspense>
            },
            {
                path: "/system/message",
                element: <Suspense fallback={fallback}><Message/></Suspense>
            }
        ]
    },
    {
        path: "/login",
        element: <Suspense fallback={fallback}><Login/></Suspense>
    },
    {
        path: "/register",
        element: <Suspense fallback={fallback}><Register/></Suspense>
    },
    {
        path: "*",
        element: <Suspense fallback={fallback}><NotFond/></Suspense>
    }
]);